package com.nulldev.util.net.experimental.udp2;

public class NetworkPackage {
	// Sequence number to keep tracking what package have been sent
    private int sequenceNumber;

    // The data that was sent with this sequence Number so we can resend it if needed
    private byte[] dataSent;

    // When did we send the data
    private long sentTime;

    // How many times the package have tried to be resent
    private int resent = 0;

    private int splitSequenceNumber;

    private boolean resentPackage = false;

    private NetworkSendType networkSendType;

    public NetworkPackage() {
    }

    public void setValues (int sequenceNumber, NetworkSendType networkSendType) {
        this.sequenceNumber = sequenceNumber;
        this.networkSendType = networkSendType;
        sentTime = System.currentTimeMillis();
        resetValues();
    }

    public void setValues (int sequenceNumber, byte[] dataSent, NetworkSendType networkSendType) {
        this.sequenceNumber = sequenceNumber;
        this.dataSent = dataSent;
        sentTime = System.currentTimeMillis();
        this.networkSendType = networkSendType;
        resetValues();
    }

    public void setValues (int sequenceNumber, byte[] dataSent, NetworkSendType networkSendType, int splitSequenceNumber) {
        this.sequenceNumber = sequenceNumber;
        this.dataSent = dataSent;
        sentTime = System.currentTimeMillis();
        this.networkSendType = networkSendType;
        this.splitSequenceNumber = splitSequenceNumber;
        resetValues();
    }

    public void resetValues() {
        resent = 0;
        resentPackage = false;
    }

/*    public NetworkPackage(int sequenceNumber, NetworkSendType networkSendType) {
        this.sequenceNumber = sequenceNumber;
        this.networkSendType = networkSendType;
        sentTime = System.currentTimeMillis();
    }
    public NetworkPackage(int sequenceNumber, byte[] dataSent, NetworkSendType networkSendType) {
        this.sequenceNumber = sequenceNumber;
        this.dataSent = dataSent;
        sentTime = System.currentTimeMillis();
        this.networkSendType = networkSendType;
    }
    public NetworkPackage(int sequenceNumber, byte[] dataSent, NetworkSendType networkSendType, int splitSequenceNumber) {
        this.sequenceNumber = sequenceNumber;
        this.dataSent = dataSent;
        sentTime = System.currentTimeMillis();
        this.networkSendType = networkSendType;
        this.splitSequenceNumber = splitSequenceNumber;
    }*/

    public void resendData(int sequenceNumber) {
        this.sequenceNumber = sequenceNumber;
        this.sentTime = System.currentTimeMillis();
        resentPackage = true;
        resent++;
    }

    public int getSequenceNumber() {
        return sequenceNumber;
    }

    public void setSequenceNumber(int sequenceNumber) {
        this.sequenceNumber = sequenceNumber;
    }

    public byte[] getDataSent() {
        return dataSent;
    }

    public long getSentTime() {
        return sentTime;
    }

    public int getResent() {
        return resent;
    }

    public NetworkSendType getNetworkSendType() {
        return networkSendType;
    }

    public int getSplitSequenceNumber() {
        return splitSequenceNumber;
    }

    public boolean isResentPackage() {
        return resentPackage;
    }
}
